/***********************************************
 This file is part of redia-library-app-ios.
 
 Copyright (c) 2012, 2013 Redia A/S
 
 Redia-library-app-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-library-app-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-library-app-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */


#import <Foundation/Foundation.h>
#import "InfoGalleriXmlRpcClient201009ChannelFetchDelegate.h"
#import "InfoObjectFetchCompleteDelegate.h"

#define ChannelFetchManager_DATA_REFRESH_TIMEOUT (30*60)

@interface ChannelFetchManager : NSObject<ChannelFetchCompleteDelegate, InfoObjectFetchCompleteDelegate> {
	bool isFetching;
	bool isFetched;
	NSMutableArray* delegates;
	//NSMutableArray* myInfoObjects;
	InfoGalleriXmlRpcClient201009ChannelFetchDelegate* igChannelFetcher;

	//NSString* projectName; //fogbugz project name
	NSString* customerId;
	NSString* galleryId;
	
	NSMutableArray* mainElements;
	NSMutableDictionary* allInfoObjects;
	
	NSDate* lastXMLRPCCallTimestamp;

}

//Get the singleton
+ (ChannelFetchManager*) instance;

//@property (nonatomic, copy) NSString* projectName;
@property (nonatomic, strong) NSMutableArray* mainElements;
@property (nonatomic, strong) NSMutableDictionary* allInfoObjects;
@property (nonatomic, strong) NSDate* lastXMLRPCCallTimestamp;
@property (nonatomic) bool createTagIndex;
@property (nonatomic) bool tagIndexCaseInsensitive;
@property (nonatomic) bool tagIndexNonstrictDelimiters;

@property (nonatomic, strong) NSMutableDictionary* tagsToInfoObjects;
@property (nonatomic) BOOL forceUseCacheData;

@property (nonatomic, strong) NSMutableArray *fetchInfoObjectDelegates;

- (void)useNewRediaPublishClient;
- (bool)isUsingNewBackend;

- (void)setCustomerDB:(NSString*)cust withGallery:(NSString*)gall;
- (void)setFetchCannelsSequentially:(BOOL)sequentially;
- (void)fetchChannels:(id<ChannelFetchCompleteDelegate>)delegate;
- (void)fetchChannelsFromPackage:(id<ChannelFetchCompleteDelegate>)delegate;
- (void)fetchChannels:(id<ChannelFetchCompleteDelegate>)delegate usingPackageSystem:(BOOL)use_package;

- (void)fetchInfoObject:(NSString*)infoObjectId delegate:(id<InfoObjectFetchCompleteDelegate>)delegate;

- (void)unregisterDelegate:(id<ChannelFetchCompleteDelegate>)delegate;

- (void)completedChannels:(int)completedNum ofTotal:(int)totalNum;
- (void)channelFetchComplete:(NSArray*) infoObjects;

- (void)addComment:(NSString *)infoObjectId authorName:(NSString *)authorName comment:(NSString *)comment authorEmail:(NSString *)authorEmail delegate:(id <XMLRPCConnectionDelegate>) d;
- (void)addVote:(NSString *)infoObjectId delegate:(id <XMLRPCConnectionDelegate>)d;

- (void)updateLastCallTimestamp;
- (BOOL)isRefreshNeeded;
- (NSString*)convertTagUsingStripping:(NSString*)orig_tag;
- (NSArray*)getObjectsForTag:(NSString*)tag;

@end
